package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.PetAdoptionInfo;
import com.itheima.pojo.Result;
import com.itheima.service.PetAdoptionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pet/petAdoInfo")
public class PetAdoptionInfoController {
    @Autowired
    private PetAdoptionInfoService petAdoptionInfoService;
    @PostMapping
    public Result add(@RequestBody @Validated(PetAdoptionInfo.Add.class) PetAdoptionInfo petAdoptionInfo){
        petAdoptionInfoService.add(petAdoptionInfo);
        return Result.success();
    }
    @DeleteMapping
    public Result<PetAdoptionInfo> delete(PetAdoptionInfo petAdoptionInfo){
        petAdoptionInfoService.delete(petAdoptionInfo);
        return Result.success();
    }
    @GetMapping
    public Result<PageBean<PetAdoptionInfo>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) String species
            ){
        PageBean<PetAdoptionInfo> pb = petAdoptionInfoService.list(pageNum,pageSize,type,species);
        return Result.success(pb);
    }
    @GetMapping("/detail")
    public Result<PetAdoptionInfo> detail(Integer id){
        PetAdoptionInfo c = petAdoptionInfoService.findById(id);
        return Result.success(c);
    }
    @PutMapping
    public Result update(@RequestBody @Validated(PetAdoptionInfo.Update.class) PetAdoptionInfo petAdoptionInfo){
        petAdoptionInfoService.update(petAdoptionInfo);
        return Result.success();
    }
    @PutMapping("/status")
    public Result updateStatus(Integer id,String status){
        petAdoptionInfoService.updateStatus(id,status);
        return Result.success();
    }
}
